<!DOCTYPE html>
<html>
<head>
	<title>Manage Traktors</title>
	<link rel="stylesheet" href="css/style.css">
</head>
<body>
	<div class="main" >
		<header id="header" class="header">
			<h1> Traktor Store</h1>
		</header>

		<nav class="menu box">
		    <p> <a href="edit.php">Add</a> </p>
		    <p> <a href="#" onclick="toDelete();"
		    >Remove</a> </p>

		    <p> <a href="#" onclick="toBuy();" >Buy</a> </p>
		    <p> <a href="logout.php">Log out</a> </p>
		</nav>

		<div class="content box">

		<?php

			$result = $data['traktors'];

			echo "<table>";
			echo "<tr> <th>Machines</th> <tr>";

			if (mysqli_num_rows($result) > 0) {
				echo "<form id=\"form\" method=\"POST\" action=\"\" >";
				while ($row = mysqli_fetch_assoc($result)) {
					echo "<tr>";
					  	echo "<td> <img src=\"".$row['image']."\" /></td>";
					  	echo "<td> <a href=\"edit.php?row=".$row['traktor_id']."\">".$row['model']."</a> </td>";
					  	echo "<td>".$row['price']."</td>";
					  	echo "<td>  <input type=\"checkbox\" name=\"traktors[]\" value=\"".$row['traktor_id']."\" > </td>";
					echo "</tr>";
				}
				echo "</form> ";
				echo "</table>";

			} else {
				echo "<p> No data found! </p>";
			}
			
		?>


		</div>
	</div>
</body>
</html>

<script>
	function toBuy() {

		document.getElementById("form").action="buy.php";
		document.getElementById('form').submit();
	}

	function toDelete() {
		
		document.getElementById("form").action="delete.php";
		document.getElementById('form').submit();
	}

</script>